﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Client.ICommandNotify
{
    public class Command :ICommand
    {
        private Action<object> addDoExecute;
        private Command? addCanExecute;

        public event EventHandler? CanExecuteChanged
        {
            add
            {
                CommandManager.RequerySuggested += value;
            }


           remove
            {
                CommandManager.RequerySuggested -= value;
            }
        }

        public bool CanExecute(object? parameter)
        {
           if(CanExecute_ == null)
            {
                return false;
            }
            else
            {
                return CanExecute_.Invoke();
            }
        }

        public void Execute(object? parameter)
        {
            DoExecute?.Invoke(parameter);
        }

        public Action<object>? DoExecute { get; set; }
        public Func<bool>? CanExecute_ { get; set; }
        public Command(Action<object>? doExecute,Func<bool>? canExecute)
        {
            DoExecute = doExecute;
            CanExecute_ = canExecute;
        }

        public Command(Action<object> addDoExecute, Command? addCanExecute)
        {
            this.addDoExecute = addDoExecute;
            this.addCanExecute = addCanExecute;
        }
    }
}
